package com.client.forms;

import java.util.Map;

import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextBox;
import com.shared.utilitaire.Adresse;

public class AdresseEditor extends DataEditor<Adresse> {

		
	private TextBox boxNumero = new TextBox();
	private ListBox comboVoie = new ListBox();
	private TextBox boxVoie = new TextBox();
	private TextBox boxCodePostal = new TextBox();
	private TextBox boxVille = new TextBox();
	private TextBox boxPays = new TextBox();
	
	public AdresseEditor() {
		edited = new Adresse();
		setSpacing(5);
		
		HorizontalPanel boxNumeroPanel = new HorizontalPanel();		
		Label labelNumero = new Label("Numero :");
		
		boxNumeroPanel.add(labelNumero);		
		boxNumeroPanel.add(boxNumero);
		add(boxNumeroPanel);
		
		HorizontalPanel typeVoiePanel = new HorizontalPanel();
		Label labelTypeVoie = new Label("Type de voie :");
		labelTypeVoie.addStyleName("gras");		
		typeVoiePanel.add(labelTypeVoie);
		comboVoie.addItem("Rue");
		comboVoie.addItem("Avenue");
		comboVoie.addItem("Blvd");
		typeVoiePanel.add(comboVoie);
		add(typeVoiePanel);
		
		HorizontalPanel voiePanel = new HorizontalPanel();
		Label labelVoie= new Label("Voie:");
		labelVoie.addStyleName("gras");
		voiePanel.add(labelVoie);
		voiePanel.add(boxVoie);
		add(voiePanel);
		
		HorizontalPanel cpPanel = new HorizontalPanel();
		Label labelCP = new Label("Code Postal :");
		labelCP.addStyleName("gras");
		cpPanel.add(labelCP);
		cpPanel.add(boxCodePostal);
		add(cpPanel);
		

		HorizontalPanel villePanel = new HorizontalPanel();
		Label labelVille = new Label("Ville :");
		labelVille.addStyleName("gras");
		villePanel.add(labelVille);
		villePanel.add(boxVille);
		add(villePanel);
		

		HorizontalPanel paysPanel = new HorizontalPanel();
		Label paysLabel = new Label("Pays :");
		paysLabel.addStyleName("gras");
		paysPanel.add(paysLabel);
		paysPanel.add(boxPays);
		add(paysPanel);
		
	}
	
	@Override
	public void fill() {
		if(edited==null) edited = new Adresse();
		boxNumero.setValue(edited.getNumero());
		if(("Rue").equals(edited.getTypeVoie())){
			comboVoie.setSelectedIndex(0);
		}else if(("Avenue").equals(edited.getTypeVoie())){
			comboVoie.setSelectedIndex(1);
		}else if(("Blvd").equals(edited.getTypeVoie())){
			comboVoie.setSelectedIndex(2);
		}else{}
		boxVoie.setValue(edited.getNomVoie());
		boxCodePostal.setValue(edited.getCodePostal());
		boxVille.setValue(edited.getVille());
		boxPays.setValue(edited.getPays());		
	}

	@Override
	public Map<String, String> getEditedAsMap() throws IllegalArgumentException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Adresse getEdited() {
		check();
		edited.setCodePostal(boxCodePostal.getValue());
		edited.setNomVoie(boxVoie.getValue());
		edited.setNumero(boxNumero.getValue());
		edited.setPays(boxPays.getValue());
		edited.setTypeVoie(comboVoie.getItemText(comboVoie.getSelectedIndex()));
		edited.setVille(boxVille.getValue());
		edited.setPays(boxPays.getValue());
		return super.getEdited();
	}
	@Override
	public void setEmpty() {
		edited = new Adresse();
		fill();		
	}

}
